package Method_References;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


public class number9 {
public static void main(String[] args) {
	
	ArrayList<String> list=new ArrayList();
	Collections.addAll(list, "张三丰,15", "张无忌,5","张翠山,50","王二麻子,25","张良,26","谢广坤,22");
	//收集到的Student类型的数组
	 Student[] students1 = list.stream()
             .map(s -> {
                 String[] parts = s.split(",");
                 return new Student(parts[0], Integer.parseInt(parts[1]));
             })
             .toArray(Student[]::new);
	 Arrays.stream(students1).forEach(System.out::print);
	 System.out.println("");
	 //创建集合添加学生对象
	 List<Student> students2 = new ArrayList<>();
	 students2.add(new Student("张三", 23));
     students2.add(new Student("李四", 24));
     students2.add(new Student("王五", 25));
     //只获取姓名并放到数组当中
     String[] array = students2.stream().map(Student::getName).toArray(String[]::new);
     Arrays.stream(array).forEach(s->System.out.print(s+" "));
     System.out.println("");
     
     //(3)创建集合添加学生对象，学生对象属性name,age
     List<Student> students3 = new ArrayList<>();
	 students3.add(new Student("张三", 23));
     students3.add(new Student("李四", 24));
     students3.add(new Student("王五", 25));
     
    System.out.println(students3+" ");
	 

}
}
